

import random;
from pyecharts.faker import Faker;
from pyecharts import options as ops;
from pyecharts.charts import Line, Line3D, Bar, Pie;

'''
pyecharts 测试
'''

def faker_test():
    print(Faker.choose());
    print(Faker.values(1, 100));
    print(Faker.rand_color());

# line test
def line_test():
    Line().add_xaxis(
        Faker.choose()
    ).add_yaxis(
        series_name="线1",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=ops.ItemStyleOpts(color=Faker.rand_color())
    ).add_yaxis(
        series_name="线2",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=ops.ItemStyleOpts(color=Faker.rand_color())
    ).set_global_opts(
        title_opts=ops.TitleOpts(title="线状图", subtitle="副标题", pos_left="10%")
    ).render(
        path="/temp/line.html"
    );

# line 3d test
def line_3d_test():
    data = [(x, y, random.randint(1, 20)) for x in range(7) for y in range(7)];
    Line3D().add(
        series_name="3dline",
        data=data,
        xaxis3d_opts=ops.Axis3DOpts(Faker.choose()),
        yaxis3d_opts=ops.Axis3DOpts(Faker.choose()),
        zaxis3d_opts=ops.Axis3DOpts(Faker.values()),
    ).set_global_opts(
        title_opts=ops.TitleOpts(title="线状3D图", subtitle="副标题", pos_left="10%")
    ).render(
        path="/temp/line3D.html"
    );

# bar test
def bar_test():
    Bar().add_xaxis(
        Faker.choose()
    ).add_yaxis(
        series_name="柱1",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=ops.ItemStyleOpts(color=Faker.rand_color())
    ).add_yaxis(
        series_name="柱2",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=ops.ItemStyleOpts(color=Faker.rand_color())
    ).set_global_opts(
        title_opts=ops.TitleOpts(title="柱状图", subtitle="副标题", pos_left="10%")
    ).render(
        path="/temp/bar.html"
    );

# pie test
def pie_test():
    # [[key, value],[key, value],[key, value]]
    data = [list(x) for x in zip(Faker.choose(), Faker.values())];
    print(data);
    Pie().add(
        series_name="饼图1",
        data_pair=data,
        rosetype="area"
    ).set_series_opts(
        label_opts=ops.LabelOpts(
            formatter="{b}:{c}",
            color=Faker.rand_color()
        )
    ).set_global_opts(
        title_opts=ops.TitleOpts(title="饼状图", subtitle="副标题", pos_left="10%")
    ).render(
        path="/temp/pie.html"
    )

if __name__ == '__main__':
    pie_test();